#include "BaseType.h"
#include "Tracer.h"
#include "ArgUtil.h"
#include "DateTime.h"
#include "Thread.h"
using namespace libemb;

 class MultiThread:public Threading{
public:
    MultiThread()
    {
        char* args = "hello";
        threading(&MultiThread::threadA1,this);
        threading(&MultiThread::threadA2,this,args);
        threading(&MultiThread::threadC,this,args,std::string("world from threading!"));

        pthreading(&MultiThread::threadB1,this);
        pthreading(&MultiThread::threadB2,this,args);
        pthreading(&MultiThread::threadC,this,args,std::string("world from pthreading!"));
        
        
    }
private:
    void threadA1()
    {
        while(1)
        {
            Thread::msleep(1000);
            TRACE_DBG_CLASS("run threadA1().");
        }
    }
    void threadA2(void* args)
    { 
        while(1)
        {
            Thread::msleep(1000);
            TRACE_DBG_CLASS("run threadA2(\"%s\").",args);
        }
    }
    void threadB1()
    {
        while(1)
        {
            Thread::msleep(1000);
            TRACE_DBG_CLASS("run threadB1().");
        }
    }
    void threadB2(void* args)
    {
        while(1)
        {
            Thread::msleep(1000);
            TRACE_DBG_CLASS("run threadB2(\"%s\").",args);
        }
    }
    void threadC(void* args,std::string info)
    {
        while(1)
        {
            Thread::msleep(1000);
            TRACE_DBG_CLASS("run threadC(\"%s\",\"%s\").",args,VSTR(info));
        }
    }
};

void testThread(void)
{
    std::unique_ptr<MultiThread> thread = nullptr;
    while(1)
    {
        TRACE_CYAN("====Test Thread====");
        TRACE_CYAN("01. start Threading.");
        TRACE_CYAN("02. stop Threading.");
        TRACE_CYAN("q . quit.");
        InputReader reader;
		reader.waitInput();
        if (reader.isString("q") || reader.isString("quit")) 
        {
            break;
        }
        else if(reader.isString("01"))
        {
            thread = std::make_unique<MultiThread>();
        }
        else if(reader.isString("02"))
        {
            thread = nullptr;
        }
    }
}

